/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sigmacinema.ui.tapestry.controller;

import com.javaforge.tapestry.spring.annotations.InjectSpring;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry.annotations.Bean;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.StringPropertySelectionModel;
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.valid.ValidationDelegate;
import sigmacinema.entity.Movie;
import sigmacinema.service.SigmaCinemaService;

/**
 *
 * @author amir
 */
public abstract class MovieController extends BasePage{
    
    @InjectSpring("SigmaCinemaService")
    public abstract SigmaCinemaService getSigmaCinemaService();
    @Bean
    public abstract ValidationDelegate getDelegate();


    private Movie movie = new Movie();
    private List<Movie> listMovie = new ArrayList<Movie>();
    
    public IPropertySelectionModel getGenreList() {
        return new StringPropertySelectionModel(new String[]{"Action", "Comedy","Drama","Horror"});
    }


    public List<Movie> getListMovie() {
        listMovie = getSigmaCinemaService().FindAllMovie();
        return listMovie;
    }

    public void setListMovie(List<Movie> listMovie) {
        this.listMovie = listMovie;
    }

    public Movie getMovie() {
        return movie;
    }

    public void setMovie(Movie movie) {
        this.movie = movie;
    }
    
    public String save(){
        ValidationDelegate delegate = getDelegate();
        if (delegate.getHasErrors()) {
            return null;
        }
        else{
            getSigmaCinemaService().saveMovie(movie);
            return "admin/ViewMovie";
        }
        
    }
}
